function submitBaseProduct()
{
	var pa = document.getElementById("errors");
	pa.innerHTML = "";
	var form = document.assemblyReleaseForm;
	if ( form.productId.value.trim() == "-1")
	{
		pa.innerHTML = "<li> Please select a valid Part number";
		form.productId.focus();
		return;
	}
	form.action.value = "partNumber";
	form.submit();
}


function submitDeviceNumber()
{
	var pa = document.getElementById("errors");
	pa.innerHTML = "";
	var form = document.assemblyReleaseForm;
	if ( form.processStepId.value.trim() == "-1")
	{
		pa.innerHTML = "<li> Please select a valid Device Name";
		form.processStepId.focus();
		return;
	}
	form.action.value = "deviceName";
	form.submit();
}


/*function submitLocation()
{
	var pa = document.getElementById("errors");
	pa.innerHTML = "";
	var form = document.assemblyReleaseForm;
	if ( form.locationId.value.trim() == "-1")
	{
		pa.innerHTML = "<li> Please select a valid Location";
		form.locationId.focus();
		return;
	}
	form.action.value = "location";
	form.submit();
}*/


function searchLotStatus()
{
	var pa = document.getElementById("errors");
	pa.innerHTML = "";
	var form = document.assemblyReleaseForm;

	if ( form.locationId.value.trim() == "-1")
	{
		pa.innerHTML = "<li> Please select a valid Assembly Location";
		form.locationId.focus();
		return;
	}
	/*
	if ( form.fromLocationId.value.trim() == "-1")
	{
		pa.innerHTML = "<li> Please select a valid From Location";
		form.fromLocationId.focus();
		return;
	}
	*/
	
	/*if ( form.lotId.value.trim() == "-1")
	{
		pa.innerHTML = "<li> Please select a valid Lot number";
		form.lotId.focus();
		return;
	}*/

	form.action.value = "lotNumber";
	form.submit();
}


function getAssemblyReleaseScreen( assemblyReleaseId, processStepId, vendorId )
{
	var pa = document.getElementById("errors");
	pa.innerHTML = "";
	var form = document.assemblyReleaseForm;
	var locationId = form.locationId.value;
	var procStepId = form.processStepId.value;
	var tempVendorId = '';
	var finalVendorId = '';
	var commaIndex = 0;

    form.assemblyReleaseIdTemp.value = assemblyReleaseId
	form.processStepIdTemp.value = processStepId;
	form.vendorIdTemp.value = vendorId;
	form.action.value = "assemblyReleaze";
	form.submit();
}


function resetPage()
{
	var form = document.assemblyReleaseForm;
	form.action.value="";
	form.submit();
}





function cancelAssemblyRelease()
{
	var form = document.assemblyReleaseForm;
	form.action.value = "cancel";
	form.submit();
}
function closeAssemblyRelease()
{
	var form = document.assemblyReleaseForm;
	form.action.value = "close";
	form.submit();
}


function shipAssemblyRelease()
{
	var form = document.assemblyReleaseForm;
	form.action.value = "ship";
	form.submit();
}


function validateReleaseDate ( dateIn )
{
	var pa = document.getElementById ( "errors" );
	pa.innerHTML = '';
	var form = document.assemblyReleaseForm;
	if ( dateIn == '' || dateIn == null )
	{
		pa.innerHTML = "<li> Please enter a value for Release Date";
		form.releaseDate.focus();
		return false;
	}
	else
	{
		if ( !chkDate ( dateIn, ' Release Date' , 'Y' ) )
		{
			pa.innerHTML = "<li> Please enter a valid Release Date and it should be in mm/dd/yyyy format";
			form.releaseDate.focus();
			return false;
		}
		else
		{
			return true;
		}
	}
}


function generateRelease()
{
	var pa = document.getElementById("errors");
	pa.innerHTML = "";
	var form = document.assemblyReleaseForm;

	var productId = form.productId.value;
	var processStepId = form.processStepId.value;
	var locationId = form.locationId.value;
	var vendorId = '';
    var count = 0;
	for( i = 0; i < form.fromLocationId.length; i++ )
	{
        if( form.fromLocationId.options[i].selected == true )
        {
            count++;
            //vendorId = vendorId + "'" + form.fromLocationId.options[i].value + "',";
            vendorId = vendorId + form.fromLocationId.options[i].value + ",";
        }
    }

    if( vendorId.length > 0 )
    {
       vendorId = vendorId.substring( 0, vendorId.length -1 )
    }

    if(count>10){
        pa.innerHTML = "<li> Please select upto 10 From Locations only to generate the assembly release";
        return;
    }

	if ( locationId == '-1' )
	{
		pa.innerHTML = "<li> Please select a valid Assembly Location to generate the assembly release";
		form.locationId.focus();
		return;
	}
	if ( vendorId == '' )
	{
		pa.innerHTML = "<li> Please select a valid From Location to generate the assembly release";
		form.fromLocationId.focus();
		return;
	}
    form.productIdTemp.value = productId;
    form.processStepIdTemp.value = processStepId;
    form.locationIdTemp.value = locationId;
    form.vendorIdTemp.value = vendorId;

    form.action.value = "new";
	form.submit();
}

function printViewAssemblyRelease( context )
{
	var form = document.assemblyReleaseForm;

	var productId=form.productId.value;
	var processStepId=form.processStepId.value;
	var fromLocationId=form.fromLocationId.value;
	var assemblyReleaseId=form.assemblyReleaseId.value;
	var deviceName = form.deviceName.value;

	var toLocationId=form.locationId.value;
	var findex=toLocationId.indexOf('/');
	var toLocationId1=toLocationId.substring(0,findex);

	var printViewAssemblyReleaseURL = context+'/assemblyRelease.do?action=printView&productId='+productId+'&processStepId='+processStepId+'&fromLocationId='+fromLocationId+'&assemblyReleaseId='+assemblyReleaseId+'&toLocationId='+toLocationId1+'&deviceName='+deviceName
	
	newWindow = window.open (printViewAssemblyReleaseURL,'assemblyReleasePopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,resizable=yes');
    newWindow.focus();
	
	/*var form = document.assemblyReleaseForm;

	var assemblyReleaseId = form.assemblyReleaseId.value;
	var processStepId = form.processStepId.value;
	var deviceName = form.deviceName.value;
	var vendorId = form.fromLocationId.value;

	var printViewAssemblyReleaseURL = '/chiptrac_cavium/assemblyRelease.do?action=printView&assemblyReleaseId=' + assemblyReleaseId + '&processStepId=' + processStepId + '&deviceName=' + deviceName + '&vendorId=' + vendorId;

	alert("printViewAssemblyReleaseURL " + printViewAssemblyReleaseURL);

    newWindow = window.open (printViewAssemblyReleaseURL,'assemblyReleasePopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,resizable=yes');
    newWindow.focus(); */
}
